include ../../Makefile.Res
ModuleName:=php

Object:=dispatch.tgz

DependLib:=libclass.so libpack.so libapi.so

DependObject:=
InstallDir:=usr/lib

.PHONY: all $(Object) $(DependObject) clean dist_clean

tmp:

all:$(Object)

$(Object):
	mkdir -p $(InstallDir)
	cd dispatch;/usr/bin/phpize;EXTRA_LDFLAGS="-lclass -lpack -lapi" ./configure; $(MAKE)
	cp dispatch/modules/dispatch.so $(InstallDir) -rf
	if [ -e libapi.so ]; then cp dispatch/*.so $(InstallDir) -rf; fi
	tar czvf $(Object) $(InstallDir)

libclass.so:
	cd dispatch; g++ -shared -o libclass.so class.cpp -Wall; cp -rf  libclass.so /usr/lib/
libpack.so:
	cd dispatch; g++ -shared -o libpack.so pack.cpp -lclass; cp -rf libpack.so /usr/lib/
libapi.so:libclass.so libpack.so
	cd dispatch;gcc -shared -o libapi.so api_test.c -lclass -lpack -ldl -rdynamic;cp -rf libapi.so /usr/lib/
clean_so:
	cd dispatch; rm *.so -rf 
	rm -rf /usr/lib/libclass.so /usr/lib/libpack.so /usr/lib/libapi.so
	
$(DependObject):
	$(MAKE) -C $@

clean:
	for i in $(DependObject) ; do $(MAKE) -C $$i clean; done
	rm -rf usr

dist_clean:clean
	for i in $(DependObject) ; do $(MAKE) -C $$i dist_clean; done
	rm -rf $(Object) 
